using micromsg;
using MicroMsg.Common.Algorithm;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Protocol;
using MicroMsg.Resource.@string;
using MicroMsg.UI.UserContrl;
using System;
namespace MicroMsg.Scene
{
	public class NetSceneSwitchPushmail : NetSceneBaseEx<SwitchPushMailRequest, SwitchPushMailResponse, SwitchPushMailRequest.Builder>
	{
		private const string TAG = "NetSceneSwitchPushmail";
		public const uint MM_FUNCTIONSWITCH_NOSUCHFUNCTION = 0u;
		public const uint MM_FUNCTIONSWITCH_OPEN = 1u;
		public const uint MM_FUNCTIONSWITCH_CLOSE = 2u;
		private bool mbOpen;
		public bool doScene(string strPwd, bool bOpen)
		{
			this.mbOpen = bOpen;
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			if (string.IsNullOrEmpty(strPwd))
			{
				this.mBuilder.SecPwdMd5 = "";
			}
			else
			{
				this.mBuilder.SecPwdMd5 = MD5Core.GetHashString(strPwd);
			}
			this.mBuilder.SwitchValue = (bOpen ? 1u : 2u);
			this.mSessionPack.mCmdUri = "/cgi-bin/micromsg-bin/switchpushmail";
			this.mSessionPack.mConnectMode = 2;
			base.endBuilder();
			return true;
		}
		protected override void onFailed(SwitchPushMailRequest request, SwitchPushMailResponse response)
		{
			Log.smethod_1("NetSceneSwitchPushmail", "SwitchPushMail failed system error!");
			EventCenter.postEvent(EventConst.ON_NETSCENE_SWITCHPUSHMAIL_ERR, null, null);
		}
		protected override void onSuccess(SwitchPushMailRequest request, SwitchPushMailResponse response)
		{
			if (response == null || response.BaseResponse.Ret != 0)
			{
				Log.smethod_1("NetSceneSwitchPushmail", "SwitchPushMail response not invalidate response.BaseResponse.Ret = " + ((RetConst)response.BaseResponse.Ret).ToString());
				if (response.BaseResponse.Ret == -31)
				{
					Dialog2BtnWithPwdBox.Show(strings.Enter_QQMail_Password, strings.Enter_QQMail_Password, strings.COM_Confirm, strings.COM_Cancel, "", new Dialog2BtnWithPwdBox.dismissWithClickBtn(this.pwdConfirmHandler), null, null);
				}
				EventCenter.postEvent(EventConst.ON_NETSCENE_SWITCHPUSHMAIL_ERR, null, null);
				return;
			}
			EventCenter.postEvent(EventConst.ON_NETSCENE_SWITCHPUSHMAIL_SUCCESS, null, null);
			if (request.SwitchValue == 1u)
			{
				AccountMgr.getCurAccount().nPushMailStatus = 1;
				AccountMgr.updateAccount();
				return;
			}
			AccountMgr.getCurAccount().nPushMailStatus = 2;
			AccountMgr.updateAccount();
		}
		private void pwdConfirmHandler(object sender, int nClickIndex)
		{
			if (nClickIndex == 0 && sender != null && sender is Dialog2BtnWithPwdBox)
			{
				Dialog2BtnWithPwdBox dialog2BtnWithPwdBox = sender as Dialog2BtnWithPwdBox;
				string password = dialog2BtnWithPwdBox.textBoxPassword.Password;
				if (!string.IsNullOrEmpty(password))
				{
					this.doScene(password, this.mbOpen);
				}
			}
		}
	}
}
